#include "Common/Collections/IIterator.h"
#include "Common/Collections/IteratorPtr.h"
#include "PropertyGridEntityViewer.h"
#include "PropertyGridPopulator.h"

PropertyGridEntityViewer::PropertyGridEntityViewer( wxPropertyGrid* propertyGrid ) :
	m_propertyGrid( propertyGrid ),
	m_entity( 0 )
{}

PropertyGridEntityViewer::~PropertyGridEntityViewer() {}

editor_core::IEntity* PropertyGridEntityViewer::GetEntity() const {
	return m_entity;
}

void PropertyGridEntityViewer::SetEntity( editor_core::IEntity* entity ) {
	if( m_entity != 0 )
		UnsetEntity();

	m_entity = entity;
	Update();
}

void PropertyGridEntityViewer::UnsetEntity() {
	if( m_entity != 0 ) {
		m_propertyGrid->Clear();
		m_entity = 0;
	}
}

void PropertyGridEntityViewer::Update() {
	if( m_entity != 0 ) {
		PropertyGridPopulator populator;
		populator.PopulateWithEntity( m_propertyGrid, m_entity );
	}
}
